[Window Captions][Getting text in general]



Recieving Messages
In the last section of API, we learned how to find findows and send messages to them. In this section we're going to go over recieving text from windows. This part is important to know becuase it can help you find windows easier by searching for certain text on labels, or by looking for a window's caption. Speaking of getting a window's caption, that's the first example i will show.
Getting Window Captions

Take a look at this code, then we'll take it apart.

(Assume Roomtitl% = handle for the chatroom window)
Lent% = GetWindowTextLength(Roomtitl%)
Strn$ = String$(200, 0)
titl% = GetWindowText(Roomtitl%, Strn$, (Lent% + 1))
Final$ = CStr(Strn$)


The first line is pretty obviouse, what it does is gets the length (Len) of the caption. So if the caption was "America Online", then Lent% would = 14.

The second line basically sets aside a string to fill with the data. the "Sting" function returns a string with the character you set aside so:
String(10,"A") returns "AAAAAAAAAA"

The third line is the one that actually gets the caption and sets it to the variable used for the String function. The syntax is like this

Variable = GetWindowText(WindowHandle,String variable,Length +1(it cuts off one))

Now Strn$ = The windows caption. I added the Final$ line just to make sure that it was in string format. CStr will convert to a string.
So now Final$ = the caption, that's it simple right?
Getting Text in General

Getting text from labels, chat rooms and etc., is slightly different.Take a look at this code:

sendnum = SendMessageByNum(Rich%, 14, 0&, 0&)
Spc$ = Space$(sendnum)
last = SendMessageByString(Rich%, 13, sendnum + 1, Spc$)


Now Spc$ hold the text
What you have to do here is send a message with a character code (Chr). In time you learn what Chr commands represent, like 13 = Enter, 9 = Tab etc.
We use 14 and 13 when getting text. 14 is used to return the length, the same way GetWindowTextLength gets the caption length.
So first we send the character 14 to the handle of the window.
Then we have to set aside another space for the text to go. This time we use the sendmessagebynum variable so that we set aside enough space to take all the text.

Then the last line is the one that actually gets the text. We use number 13 here to get it. Remember to add one to the length all the time.